* Replication Code for:
* Aspiration versus Apprehension: Economic Opportunities and Electoral Preferences
* Silja Häusermann, Thomas Kurer and Delia Zollinger
* British Journal of Political Science
* 2023

* Supplementary Material Appendix F
* Figures F.1-F.12

clear

set scheme plottig

global datpath "...set path..."
global outpath "...set path..."

* run aspiration_apprehension_replication.R first to create dataset op_for_stata.csv
import delimited "$datpath/op_for_stata.csv"

gen age_grp3=.
replace age_grp3=1 if age_grp=="18-25" | age_grp=="26-35"
replace age_grp3=2 if age_grp=="36-45" | age_grp=="46-55"
replace age_grp3=3 if age_grp=="56-65" | age_grp=="66+"
label variable age_grp3 "age group"
label define age_grp3 1 "young" 2 "mid" 3 "old" 
label values age_grp3 age_grp3

gen educ_grp3=.
replace educ_grp3=1 if educ_grp2=="low"
replace educ_grp3=2 if educ_grp2=="medium"
replace educ_grp3=3 if educ_grp2=="high"
label variable educ_grp3 "educ group"
label define educ_grp3 1 "low" 2 "medium" 3 "high" 
label values educ_grp3 educ_grp3

egen oesch=group(class8)
labmask oesch, values(class8)


egen cntry=group(country)
labmask cntry, values(country)

gen taskgroup3=.
replace taskgroup3=1 if taskgroup=="non-routine manual"
replace taskgroup3=2 if taskgroup=="routine"
replace taskgroup3=3 if taskgroup=="non-routine cognitive"
label variable taskgroup3 "taskgroup"
label define taskgroup3 1 "non-routine manual" 2 "routine" 3 "non-routine cognitive" 
label values taskgroup3 taskgroup3

label variable female "gender"
label define female 0 "male" 1 "female" 
label values female female

gen qr=.
replace qr=1 if quadrant=="comfortable"
replace qr=2 if quadrant=="apprehensive"
replace qr=3 if quadrant=="aspirational"
replace qr=4 if quadrant=="burdened"
label variable qr "quadrant"
label define qr 1 "comfortable" 2 "apprehensive" 3 "aspirational" 4 "burdened"
label values qr qr


mlogit qr i.female i.age_grp3 i.educ_grp3 i.oesch i.cntry

quietly describe female age_grp3 educ_grp3 oesch cntry, varlist
local vars = r(varlist)
foreach x of varlist `vars'{

graph drop _all

margins `x', atmeans predict(outcome(1))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr1) 
margins `x', atmeans predict(outcome(2))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr2) 
margins `x', atmeans predict(outcome(3))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr3) 
margins `x', atmeans predict(outcome(4))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr4) 
graph combine qr1 qr2 qr3 qr4, ycommon xsize(12) ysize(12)  title("Vars in Mod: `vars'")
graph export "$outpath/mn_`x'.pdf", replace

}

mlogit qr i.female i.age_grp3 i.educ_grp3 i.taskgroup3 i.cntry
graph drop _all

margins taskgroup3, atmeans predict(outcome(1))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr1) 
margins taskgroup3, atmeans predict(outcome(2))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr2) 
margins taskgroup3, atmeans predict(outcome(3))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr3) 
margins taskgroup3, atmeans predict(outcome(4))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr4) 
graph combine qr1 qr2 qr3 qr4, ycommon xsize(12) ysize(12)  title("Vars in Mod: female age_grp3 educ_grp3 taskgroup3 cntry")
graph export "$outpath/mn_taskgroup3.pdf", replace

* interactions

mlogit qr i.female##i.age_grp3 i.educ_grp3 i.oesch i.cntry
graph drop _all

margins age_grp3#female, atmeans predict(outcome(1))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr1) 
margins age_grp3#female, atmeans predict(outcome(2))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr2) 
margins age_grp3#female, atmeans predict(outcome(3))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr3) 
margins age_grp3#female, atmeans predict(outcome(4))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr4) 
graph combine qr1 qr2 qr3 qr4, ycommon xsize(12) ysize(12)  title("Vars in Mod: female age_grp3 educ_grp3 oesch cntry")
graph export "$outpath/mn_age_by_gender.pdf", replace

mlogit qr i.female##i.educ_grp3 i.age_grp3 i.oesch i.cntry
graph drop _all

margins educ_grp3#female, atmeans predict(outcome(1))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr1) 
margins educ_grp3#female, atmeans predict(outcome(2))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr2) 
margins educ_grp3#female, atmeans predict(outcome(3))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr3) 
margins educ_grp3#female, atmeans predict(outcome(4))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr4) 
graph combine qr1 qr2 qr3 qr4, ycommon xsize(12) ysize(12)  title("Vars in Mod: female age_grp3 educ_grp3 oesch cntry")
graph export "$outpath/mn_edu_by_gender.pdf", replace

mlogit qr i.female##i.oesch i.age_grp3 i.educ_grp3  i.cntry
graph drop _all

margins oesch#female, atmeans predict(outcome(1))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr1) 
margins oesch#female, atmeans predict(outcome(2))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr2) 
margins oesch#female, atmeans predict(outcome(3))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr3) 
margins oesch#female, atmeans predict(outcome(4))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr4) 
graph combine qr1 qr2 qr3 qr4, ycommon xsize(12) ysize(12)  title("Vars in Mod: female age_grp3 educ_grp3 oesch cntry")
graph export "$outpath/mn_oesch_by_gender.pdf", replace

mlogit qr i.female##i.taskgroup3 i.age_grp3 i.educ_grp3  i.cntry
graph drop _all

margins taskgroup3#female, atmeans predict(outcome(1))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr1) 
margins taskgroup3#female, atmeans predict(outcome(2))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr2) 
margins taskgroup3#female, atmeans predict(outcome(3))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr3) 
margins taskgroup3#female, atmeans predict(outcome(4))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr4) 
graph combine qr1 qr2 qr3 qr4, ycommon xsize(12) ysize(12)  title("Vars in Mod: female age_grp3 educ_grp3 taskgroup3 cntry")
graph export "$outpath/mn_taskgroup3_by_gender.pdf", replace

mlogit qr i.age_grp3##female i.educ_grp3 i.oesch i.cntry
graph drop _all

margins female#age_grp3, atmeans predict(outcome(1))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr1) 
margins female#age_grp3, atmeans predict(outcome(2))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr2) 
margins female#age_grp3, atmeans predict(outcome(3))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr3) 
margins female#age_grp3, atmeans predict(outcome(4))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr4) 
graph combine qr1 qr2 qr3 qr4, ycommon xsize(12) ysize(12)  title("Vars in Mod: age_grp3 age_grp3 educ_grp3 oesch cntry")
graph export "$outpath/mn_gender_by_age.pdf", replace

mlogit qr i.age_grp3##i.educ_grp3 i.age_grp3 i.oesch i.cntry
graph drop _all

margins educ_grp3#age_grp3, atmeans predict(outcome(1))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr1) 
margins educ_grp3#age_grp3, atmeans predict(outcome(2))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr2) 
margins educ_grp3#age_grp3, atmeans predict(outcome(3))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr3) 
margins educ_grp3#age_grp3, atmeans predict(outcome(4))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr4) 
graph combine qr1 qr2 qr3 qr4, ycommon xsize(12) ysize(12)  title("Vars in Mod: age_grp3 age_grp3 educ_grp3 oesch cntry")
graph export "$outpath/mn_edu_by_age.pdf", replace

mlogit qr i.age_grp3##i.oesch i.age_grp3 i.educ_grp3  i.cntry
graph drop _all

margins oesch#age_grp3, atmeans predict(outcome(1))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr1) 
margins oesch#age_grp3, atmeans predict(outcome(2))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr2) 
margins oesch#age_grp3, atmeans predict(outcome(3))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr3) 
margins oesch#age_grp3, atmeans predict(outcome(4))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr4) 
graph combine qr1 qr2 qr3 qr4, ycommon xsize(12) ysize(12)  title("Vars in Mod: age_grp3 age_grp3 educ_grp3 oesch cntry")
graph export "$outpath/mn_oesch_by_age.pdf", replace

mlogit qr i.age_grp3##i.taskgroup3 i.age_grp3 i.educ_grp3  i.cntry
graph drop _all

margins taskgroup3#age_grp3, atmeans predict(outcome(1))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr1) 
margins taskgroup3#age_grp3, atmeans predict(outcome(2))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr2) 
margins taskgroup3#age_grp3, atmeans predict(outcome(3))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr3) 
margins taskgroup3#age_grp3, atmeans predict(outcome(4))
marginsplot, title("") xlabel(, angle(45)) xtitle("")  aspectratio(1) graphregion(margin(zero)) name(qr4) 
graph combine qr1 qr2 qr3 qr4, ycommon xsize(12) ysize(12)  title("Vars in Mod: age_grp3 age_grp3 educ_grp3 taskgroup3 cntry")
graph export "$outpath/mn_taskgroup3_by_age.pdf", replace



